package cn.com.nr.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.stereotype.Controller;

import cn.com.common.constants.Constants;
import cn.com.common.result.DataResult;
import cn.com.gas.constants.GasConstants;

import cn.com.gas.entity.GasStationinfoEntity;

import cn.com.gas.service.GasStationinfoService;
import cn.com.nr.entity.NrConcreteEndangerEntity;
import cn.com.nr.entity.NrDiggingsEndangerEntity;
import cn.com.nr.entity.NrRecordsEntity;
import cn.com.nr.service.NrConcreteEndangerService;
import cn.com.nr.service.NrDiggingsEndangerService;
import cn.com.nr.service.NrRecordsService;
import cn.com.system.service.impl.HttpSessionService;
import cn.com.util.TsBqUtils;
import io.swagger.annotations.ApiOperation;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 首页
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2024-03-24 01:14:06
 */
@Controller
@RequestMapping("/nr/homemain")
public class NrHomeMainController {
	
	@Autowired
	private NrDiggingsEndangerService nrDiggingsEndangerService;
	@Autowired
	private NrConcreteEndangerService nrConcreteEndangerService;
	
	@Autowired
	private NrRecordsService nrRecordsService;
	
	@Autowired
	private GasStationinfoService gasStationinfoService;
	
	@Autowired
	private HttpSessionService httpSessionService;
	
	
	@ApiOperation(value = "首页h2标签数据")
	@PostMapping("/h2data")
	@ResponseBody
	public DataResult h2data() throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		LocalDate today = LocalDate.now();
	    LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
	    LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
	    
		List<Map<String,Object>> list = new ArrayList<>();
		
		String currentDeptId = httpSessionService.getCurrentDeptId();

		// 铁矿采矿 
		int collectCount = 0;
		int collectCamCount = 0;
		int collectCamoffCount = 0; // 离线
		int collectCamonCount = 0; // 在线
		int collectRecords = 0; // 车流
		// 计算企业
		LambdaQueryWrapper<NrDiggingsEndangerEntity> queryWrapperCollect = Wrappers.lambdaQuery();
		if (Constants.TAX_COUNTES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 县区局
			queryWrapperCollect.eq(NrDiggingsEndangerEntity::getTaxorgcode, currentDeptId);
		} else if (Constants.TAX_CITIES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 市局
			queryWrapperCollect.like(NrDiggingsEndangerEntity::getTaxorgcode, currentDeptId.substring(0, 5));
		} else {
			// 省局
		}
		
		queryWrapperCollect.eq(NrDiggingsEndangerEntity::getIndustry,"铁矿采矿");
		List<NrDiggingsEndangerEntity> listCollect = nrDiggingsEndangerService.list(queryWrapperCollect);

		collectCount = listCollect.size();
		
		List<String> listCollectCountId = new ArrayList<>();
		for (NrDiggingsEndangerEntity entityCollect : listCollect) {
			String id = entityCollect.getId();
			listCollectCountId.add(id);
		}
		// 计算摄像头
		if(TsBqUtils.isNotNull(listCollectCountId)){
			LambdaQueryWrapper<GasStationinfoEntity> queryWrapperCollectCam = Wrappers.lambdaQuery();
			queryWrapperCollectCam.in(GasStationinfoEntity::getPid, listCollectCountId);
			queryWrapperCollectCam.eq(GasStationinfoEntity::getType, "cam");
			List<GasStationinfoEntity> listCollectCam = gasStationinfoService.list(queryWrapperCollectCam);
			
			for (GasStationinfoEntity gasStationinfoEntity : listCollectCam) {
				String iconSkin = gasStationinfoEntity.getIconSkin();
				if(iconSkin.equals(GasConstants.ICON_SKIN_OFF)){
					// 离线
					collectCamoffCount ++;
				}else{
					// 在线
					collectCamonCount ++;
				}
			}
		}
		// 计算车流
		if(TsBqUtils.isNotNull(listCollectCountId)){
			LambdaQueryWrapper<NrRecordsEntity> queryWrapperCollectRecords = Wrappers.lambdaQuery();
			queryWrapperCollectRecords.in(NrRecordsEntity::getNrEndanger, listCollectCountId);
			queryWrapperCollectRecords.ge(NrRecordsEntity::getTime, sdf.parse(firstDayOfMonth.toString() + " 00:00:00"));
			queryWrapperCollectRecords.le(NrRecordsEntity::getTime,sdf.parse(lastDayOfMonth.toString() + " 23:59:59"));
			queryWrapperCollectRecords.orderByDesc(NrRecordsEntity::getTime);
			
			collectRecords = nrRecordsService.count(queryWrapperCollectRecords);
		}
		
		
		
		// 铁矿选矿
		int selectCount = 0;
		int selectCamCount = 0;
		int selectCamoffCount = 0; // 离线
		int selectCamonCount = 0; // 在线
		int selectRecords = 0; // 车流
		// 计算企业
		LambdaQueryWrapper<NrDiggingsEndangerEntity> queryWrapperSelect = Wrappers.lambdaQuery();
		if (Constants.TAX_COUNTES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 县区局
			queryWrapperSelect.eq(NrDiggingsEndangerEntity::getTaxorgcode, currentDeptId);
		} else if (Constants.TAX_CITIES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 市局
			queryWrapperSelect.like(NrDiggingsEndangerEntity::getTaxorgcode, currentDeptId.substring(0, 5));
		} else {
			// 省局
		}
		
		queryWrapperSelect.eq(NrDiggingsEndangerEntity::getIndustry,"铁矿选矿");
		List<NrDiggingsEndangerEntity> listSelect = nrDiggingsEndangerService.list(queryWrapperSelect);

		selectCount = listSelect.size();
		
		List<String> listSelectCountId = new ArrayList<>();
		for (NrDiggingsEndangerEntity entitySelect : listSelect) {
			String id = entitySelect.getId();
			listSelectCountId.add(id);
		}
		// 计算摄像头
		if(TsBqUtils.isNotNull(listSelectCountId)){
			LambdaQueryWrapper<GasStationinfoEntity> queryWrapperSelectCam = Wrappers.lambdaQuery();
			queryWrapperSelectCam.in(GasStationinfoEntity::getPid, listSelectCountId);
			queryWrapperSelectCam.eq(GasStationinfoEntity::getType, "cam");
			List<GasStationinfoEntity> listSelectCam = gasStationinfoService.list(queryWrapperSelectCam);
			for (GasStationinfoEntity gasStationinfoEntity : listSelectCam) {
				String iconSkin = gasStationinfoEntity.getIconSkin();
				if(iconSkin.equals(GasConstants.ICON_SKIN_OFF)){
					// 离线
					selectCamoffCount ++;
				}else{
					// 在线
					selectCamonCount ++;
				}
			}
		}
		// 计算车流
		if(TsBqUtils.isNotNull(listSelectCountId)){
			LambdaQueryWrapper<NrRecordsEntity> queryWrapperSelectRecords = Wrappers.lambdaQuery();
			queryWrapperSelectRecords.in(NrRecordsEntity::getNrEndanger, listSelectCountId);
			queryWrapperSelectRecords.ge(NrRecordsEntity::getTime, sdf.parse(firstDayOfMonth.toString() + " 00:00:00"));
			queryWrapperSelectRecords.le(NrRecordsEntity::getTime,sdf.parse(lastDayOfMonth.toString() + " 23:59:59"));
			queryWrapperSelectRecords.orderByDesc(NrRecordsEntity::getTime);
			
			selectRecords = nrRecordsService.count(queryWrapperSelectRecords);
		}
		
		// 水泥制造
		int makeCount = 0;
		int makeCamCount = 0;
		int makeCamoffCount = 0; // 离线
		int makeCamonCount = 0; // 在线
		int makeRecords = 0; // 车流
		// 计算企业
		LambdaQueryWrapper<NrConcreteEndangerEntity> queryWrapperMake = Wrappers.lambdaQuery();
		if (Constants.TAX_COUNTES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 县区局
			queryWrapperMake.eq(NrConcreteEndangerEntity::getTaxorgcode, currentDeptId);
		} else if (Constants.TAX_CITIES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 市局
			queryWrapperMake.like(NrConcreteEndangerEntity::getTaxorgcode, currentDeptId.substring(0, 5));
		} else {
			// 省局
		}
		
		queryWrapperMake.eq(NrConcreteEndangerEntity::getIndustry,"水泥制造");
		List<NrConcreteEndangerEntity> listMake = nrConcreteEndangerService.list(queryWrapperMake);

		makeCount = listMake.size();
		
		List<String> listMakeCountId = new ArrayList<>();
		for (NrConcreteEndangerEntity entityMake : listMake) {
			String id = entityMake.getId();
			listMakeCountId.add(id);
		}
		// 计算摄像头
		if(TsBqUtils.isNotNull(listMakeCountId)){
			LambdaQueryWrapper<GasStationinfoEntity> queryWrapperMakeCam = Wrappers.lambdaQuery();
			queryWrapperMakeCam.in(GasStationinfoEntity::getPid, listMakeCountId);
			queryWrapperMakeCam.eq(GasStationinfoEntity::getType, "cam");
			List<GasStationinfoEntity> listMakeCam = gasStationinfoService.list(queryWrapperMakeCam);
			for (GasStationinfoEntity gasStationinfoEntity : listMakeCam) {
				String iconSkin = gasStationinfoEntity.getIconSkin();
				if(iconSkin.equals(GasConstants.ICON_SKIN_OFF)){
					// 离线
					makeCamoffCount ++;
				}else{
					// 在线
					makeCamonCount ++;
				}
			}
		}
		// 计算车流
		if(TsBqUtils.isNotNull(listMakeCountId)){
			LambdaQueryWrapper<NrRecordsEntity> queryWrapperMakeRecords = Wrappers.lambdaQuery();
			queryWrapperMakeRecords.in(NrRecordsEntity::getNrEndanger, listMakeCountId);
			queryWrapperMakeRecords.ge(NrRecordsEntity::getTime, sdf.parse(firstDayOfMonth.toString() + " 00:00:00"));
			queryWrapperMakeRecords.le(NrRecordsEntity::getTime,sdf.parse(lastDayOfMonth.toString() + " 23:59:59"));
			queryWrapperMakeRecords.orderByDesc(NrRecordsEntity::getTime);
			
			makeRecords = nrRecordsService.count(queryWrapperMakeRecords);
		}
		
		
		// 混凝土
		int applyCount = 0;
		int applyCamCount = 0;
		int applyCamoffCount = 0; // 离线
		int applyCamonCount = 0; // 在线
		int applyRecords = 0; // 车流
		// 计算企业
		LambdaQueryWrapper<NrConcreteEndangerEntity> queryWrapperApply = Wrappers.lambdaQuery();
		if (Constants.TAX_COUNTES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 县区局
			queryWrapperApply.eq(NrConcreteEndangerEntity::getTaxorgcode, currentDeptId);
		} else if (Constants.TAX_CITIES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 市局
			queryWrapperApply.like(NrConcreteEndangerEntity::getTaxorgcode, currentDeptId.substring(0, 5));
		} else {
			// 省局
		}
		
		queryWrapperApply.eq(NrConcreteEndangerEntity::getIndustry,"混凝土");
		List<NrConcreteEndangerEntity> listApply = nrConcreteEndangerService.list(queryWrapperApply);

		applyCount = listApply.size();
		
		List<String> listApplyCountId = new ArrayList<>();
		for (NrConcreteEndangerEntity entityApply : listApply) {
			String id = entityApply.getId();
			listApplyCountId.add(id);
		}
		// 计算摄像头
		if(TsBqUtils.isNotNull(listApplyCountId)){
			LambdaQueryWrapper<GasStationinfoEntity> queryWrapperApplyCam = Wrappers.lambdaQuery();
			queryWrapperApplyCam.in(GasStationinfoEntity::getPid, listApplyCountId);
			queryWrapperApplyCam.eq(GasStationinfoEntity::getType, "cam");
			List<GasStationinfoEntity> listApplyCam = gasStationinfoService.list(queryWrapperApplyCam);
			for (GasStationinfoEntity gasStationinfoEntity : listApplyCam) {
				String iconSkin = gasStationinfoEntity.getIconSkin();
				if(iconSkin.equals(GasConstants.ICON_SKIN_OFF)){
					// 离线
					applyCamoffCount ++;
				}else{
					// 在线
					applyCamonCount ++;
				}
			}
		}
		// 计算车流
		if(TsBqUtils.isNotNull(listApplyCountId)){
			LambdaQueryWrapper<NrRecordsEntity> queryWrapperApplyRecords = Wrappers.lambdaQuery();
			queryWrapperApplyRecords.in(NrRecordsEntity::getNrEndanger, listApplyCountId);
			queryWrapperApplyRecords.ge(NrRecordsEntity::getTime, sdf.parse(firstDayOfMonth.toString() + " 00:00:00"));
			queryWrapperApplyRecords.le(NrRecordsEntity::getTime,sdf.parse(lastDayOfMonth.toString() + " 23:59:59"));
			queryWrapperApplyRecords.orderByDesc(NrRecordsEntity::getTime);
			
			applyRecords = nrRecordsService.count(queryWrapperApplyRecords);
		}
		
		Map<String,Object> collectCountMap = new HashMap<String, Object>();
		collectCountMap.put("collectCount", collectCount);
		Map<String,Object> collectCamCountMap = new HashMap<String, Object>();
		collectCamCountMap.put("collectCamCount",collectCamoffCount + collectCamonCount);
		Map<String,Object> collectCamoffCountMap = new HashMap<String, Object>();
		collectCamoffCountMap.put("collectCamoffCount",collectCamoffCount);
		Map<String,Object> collectCamonCountMap = new HashMap<String, Object>();
		collectCamonCountMap.put("collectCamonCount",collectCamonCount);
		Map<String,Object> collectRecordsMap = new HashMap<String, Object>();
		collectRecordsMap.put("collectRecords",collectRecords);
		
		
		Map<String,Object> selectCountMap = new HashMap<String, Object>();
		selectCountMap.put("selectCount", selectCount);
		Map<String,Object> selectCamCountMap = new HashMap<String, Object>();
		selectCamCountMap.put("selectCamCount",selectCamoffCount + selectCamonCount);
		Map<String,Object> selectCamoffCountMap = new HashMap<String, Object>();
		selectCamoffCountMap.put("selectCamoffCount",selectCamoffCount);
		Map<String,Object> selectCamonCountMap = new HashMap<String, Object>();
		selectCamonCountMap.put("selectCamonCount",selectCamonCount);
		Map<String,Object> selectRecordsMap = new HashMap<String, Object>();
		selectRecordsMap.put("selectRecords",selectRecords);
		
		
		Map<String,Object> makeCountMap = new HashMap<String, Object>();
		makeCountMap.put("makeCount", makeCount);
		Map<String,Object> makeCamCountMap = new HashMap<String, Object>();
		makeCamCountMap.put("makeCamCount",makeCamoffCount + makeCamonCount);
		Map<String,Object> makeCamoffCountMap = new HashMap<String, Object>();
		makeCamoffCountMap.put("makeCamoffCount",makeCamoffCount);
		Map<String,Object> makeCamonCountMap = new HashMap<String, Object>();
		makeCamonCountMap.put("makeCamonCount",makeCamonCount);
		Map<String,Object> makeRecordsMap = new HashMap<String, Object>();
		makeRecordsMap.put("makeRecords",makeRecords);
		
		
		Map<String,Object> applyCountMap = new HashMap<String, Object>();
		applyCountMap.put("applyCount", applyCount);
		Map<String,Object> applyCamCountMap = new HashMap<String, Object>();
		applyCamCountMap.put("applyCamCount",applyCamoffCount + applyCamonCount);
		Map<String,Object> applyCamoffCountMap = new HashMap<String, Object>();
		applyCamoffCountMap.put("applyCamoffCount",applyCamoffCount);
		Map<String,Object> applyCamonCountMap = new HashMap<String, Object>();
		applyCamonCountMap.put("applyCamonCount",applyCamonCount);
		Map<String,Object> applyRecordsMap = new HashMap<String, Object>();
		applyRecordsMap.put("applyRecords",applyRecords);
		
		list.add(collectCountMap);
		list.add(collectCamCountMap);
		list.add(collectCamoffCountMap);
		list.add(collectCamonCountMap);
		list.add(collectRecordsMap);
		
		list.add(selectCountMap);
		list.add(selectCamCountMap);
		list.add(selectCamoffCountMap);
		list.add(selectCamonCountMap);
		list.add(selectRecordsMap);
		
		list.add(makeCountMap);
		list.add(makeCamCountMap);
		list.add(makeCamoffCountMap);
		list.add(makeCamonCountMap);
		list.add(makeRecordsMap);
		
		list.add(applyCountMap);
		list.add(applyCamCountMap);
		list.add(applyCamoffCountMap);
		list.add(applyCamonCountMap);
		list.add(applyRecordsMap);
		
		return DataResult.success(list);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@ApiOperation(value = "获取停留时间TOP数据")
	@PostMapping("/staytimeTop")
	@ResponseBody
	public DataResult staytimeTop(@RequestBody NrRecordsEntity nrRecordsEntity) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		LocalDate today = LocalDate.now();
	    LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
	    LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
		
		String currentDeptId = httpSessionService.getCurrentDeptId();
		
		List<List<NrRecordsEntity>> list = new ArrayList<>();
		
		
		// 铁矿采矿 
		LambdaQueryWrapper<NrDiggingsEndangerEntity> queryWrapperCollect = Wrappers.lambdaQuery();
		if (Constants.TAX_COUNTES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 县区局
			queryWrapperCollect.eq(NrDiggingsEndangerEntity::getTaxorgcode, currentDeptId);
		} else if (Constants.TAX_CITIES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 市局
			queryWrapperCollect.like(NrDiggingsEndangerEntity::getTaxorgcode, currentDeptId.substring(0, 5));
		} else {
			// 省局
		}
				
		queryWrapperCollect.eq(NrDiggingsEndangerEntity::getIndustry,"铁矿采矿");
		List<NrDiggingsEndangerEntity> listCollect = nrDiggingsEndangerService.list(queryWrapperCollect);
		List<String> listCollectCountId = new ArrayList<>();
		for (NrDiggingsEndangerEntity entityCollect : listCollect) {
			String id = entityCollect.getId();
			listCollectCountId.add(id);
		}
				
		// 计算车流
		if(TsBqUtils.isNotNull(listCollectCountId)){
			Page page = new Page(nrRecordsEntity.getPage(), nrRecordsEntity.getLimit());
			LambdaQueryWrapper<NrRecordsEntity> queryWrapperCollectRecords = Wrappers.lambdaQuery();
			queryWrapperCollectRecords.in(NrRecordsEntity::getNrEndanger, listCollectCountId);
			queryWrapperCollectRecords.ge(NrRecordsEntity::getTime, sdf.parse(firstDayOfMonth.toString() + " 00:00:00"));
			queryWrapperCollectRecords.le(NrRecordsEntity::getTime,sdf.parse(lastDayOfMonth.toString() + " 23:59:59"));
			queryWrapperCollectRecords.orderByDesc(NrRecordsEntity::getTime);
			
			IPage<NrRecordsEntity> iPageCollect = nrRecordsService.page(page,queryWrapperCollectRecords);
			List<NrRecordsEntity> recordsCollect = iPageCollect.getRecords();
			for (NrRecordsEntity records : recordsCollect) {
				String nrEndanger = records.getNrEndanger();
				records.setNrEndangerName(gasStationinfoService.getById(nrEndanger).getName());
			}
			
			list.add(recordsCollect);
		}
				
		// 铁矿选矿
		LambdaQueryWrapper<NrDiggingsEndangerEntity> queryWrapperSelect = Wrappers.lambdaQuery();
		if (Constants.TAX_COUNTES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 县区局
			queryWrapperSelect.eq(NrDiggingsEndangerEntity::getTaxorgcode, currentDeptId);
		} else if (Constants.TAX_CITIES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 市局
			queryWrapperSelect.like(NrDiggingsEndangerEntity::getTaxorgcode, currentDeptId.substring(0, 5));
		} else {
			// 省局
		}
		
		queryWrapperSelect.eq(NrDiggingsEndangerEntity::getIndustry,"铁矿选矿");
		List<NrDiggingsEndangerEntity> listSelect = nrDiggingsEndangerService.list(queryWrapperSelect);

		
		List<String> listSelectCountId = new ArrayList<>();
		for (NrDiggingsEndangerEntity entitySelect : listSelect) {
			String id = entitySelect.getId();
			listSelectCountId.add(id);
		}
				
		// 计算车流
		if(TsBqUtils.isNotNull(listSelectCountId)){
			Page page = new Page(nrRecordsEntity.getPage(), nrRecordsEntity.getLimit());
			LambdaQueryWrapper<NrRecordsEntity> queryWrapperSelectRecords = Wrappers.lambdaQuery();
			queryWrapperSelectRecords.in(NrRecordsEntity::getNrEndanger, listSelectCountId);
			queryWrapperSelectRecords.ge(NrRecordsEntity::getTime, sdf.parse(firstDayOfMonth.toString() + " 00:00:00"));
			queryWrapperSelectRecords.le(NrRecordsEntity::getTime,sdf.parse(lastDayOfMonth.toString() + " 23:59:59"));
			queryWrapperSelectRecords.orderByDesc(NrRecordsEntity::getTime);
			
			IPage<NrRecordsEntity> iPageSelect = nrRecordsService.page(page,queryWrapperSelectRecords);
			List<NrRecordsEntity> recordsSelect = iPageSelect.getRecords();
			for (NrRecordsEntity records : recordsSelect) {
				String nrEndanger = records.getNrEndanger();
				records.setNrEndangerName(gasStationinfoService.getById(nrEndanger).getName());
			}
			
			list.add(recordsSelect);
		}
				
		// 水泥制造
				
		LambdaQueryWrapper<NrConcreteEndangerEntity> queryWrapperMake = Wrappers.lambdaQuery();
		if (Constants.TAX_COUNTES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 县区局
			queryWrapperMake.eq(NrConcreteEndangerEntity::getTaxorgcode, currentDeptId);
		} else if (Constants.TAX_CITIES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 市局
			queryWrapperMake.like(NrConcreteEndangerEntity::getTaxorgcode, currentDeptId.substring(0, 5));
		} else {
			// 省局
		}
				
		queryWrapperMake.eq(NrConcreteEndangerEntity::getIndustry,"水泥制造");
		List<NrConcreteEndangerEntity> listMake = nrConcreteEndangerService.list(queryWrapperMake);

		List<String> listMakeCountId = new ArrayList<>();
		for (NrConcreteEndangerEntity entityMake : listMake) {
			String id = entityMake.getId();
			listMakeCountId.add(id);
		}
				
		// 计算车流
		if(TsBqUtils.isNotNull(listMakeCountId)){
			Page page = new Page(nrRecordsEntity.getPage(), nrRecordsEntity.getLimit());
			LambdaQueryWrapper<NrRecordsEntity> queryWrapperMakeRecords = Wrappers.lambdaQuery();
			queryWrapperMakeRecords.in(NrRecordsEntity::getNrEndanger, listMakeCountId);
			queryWrapperMakeRecords.ge(NrRecordsEntity::getTime, sdf.parse(firstDayOfMonth.toString() + " 00:00:00"));
			queryWrapperMakeRecords.le(NrRecordsEntity::getTime,sdf.parse(lastDayOfMonth.toString() + " 23:59:59"));
			queryWrapperMakeRecords.orderByDesc(NrRecordsEntity::getTime);
			
			IPage<NrRecordsEntity> iPageMake = nrRecordsService.page(page,queryWrapperMakeRecords);
			List<NrRecordsEntity> recordsMake = iPageMake.getRecords();
			for (NrRecordsEntity records : recordsMake) {
				String nrEndanger = records.getNrEndanger();
				records.setNrEndangerName(gasStationinfoService.getById(nrEndanger).getName());
			}
			list.add(recordsMake);
		}
				
		// 混凝土
		LambdaQueryWrapper<NrConcreteEndangerEntity> queryWrapperApply = Wrappers.lambdaQuery();
		if (Constants.TAX_COUNTES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 县区局
			queryWrapperApply.eq(NrConcreteEndangerEntity::getTaxorgcode, currentDeptId);
		} else if (Constants.TAX_CITIES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))) {
			// 市局
			queryWrapperApply.like(NrConcreteEndangerEntity::getTaxorgcode, currentDeptId.substring(0, 5));
		} else {
			// 省局
		}
		
		queryWrapperApply.eq(NrConcreteEndangerEntity::getIndustry,"混凝土");
		List<NrConcreteEndangerEntity> listApply = nrConcreteEndangerService.list(queryWrapperApply);

		List<String> listApplyCountId = new ArrayList<>();
		for (NrConcreteEndangerEntity entityApply : listApply) {
			String id = entityApply.getId();
			listApplyCountId.add(id);
		}
				
		// 计算车流
		if(TsBqUtils.isNotNull(listApplyCountId)){
			Page page = new Page(nrRecordsEntity.getPage(), nrRecordsEntity.getLimit());
			LambdaQueryWrapper<NrRecordsEntity> queryWrapperApplyRecords = Wrappers.lambdaQuery();
			queryWrapperApplyRecords.in(NrRecordsEntity::getNrEndanger, listApplyCountId);
			queryWrapperApplyRecords.ge(NrRecordsEntity::getTime, sdf.parse(firstDayOfMonth.toString() + " 00:00:00"));
			queryWrapperApplyRecords.le(NrRecordsEntity::getTime,sdf.parse(lastDayOfMonth.toString() + " 23:59:59"));
			queryWrapperApplyRecords.orderByDesc(NrRecordsEntity::getTime);
			
			IPage<NrRecordsEntity> iPageApply = nrRecordsService.page(page,queryWrapperApplyRecords);
			List<NrRecordsEntity> recordsApply = iPageApply.getRecords();
			for (NrRecordsEntity records : recordsApply) {
				String nrEndanger = records.getNrEndanger();
				records.setNrEndangerName(gasStationinfoService.getById(nrEndanger).getName());
			}
			
			list.add(recordsApply);
		}
		
		return DataResult.success(list);
	}
	
	
}
